inherited fmKitchen: TfmKitchen
  Left = 431
  Top = 144
  Width = 1068
  Height = 495
  Caption = 'fmKitchen'
  OnShow = FormShow
  PixelsPerInch = 96
  TextHeight = 13
  inherited sbBottom: TStatusBar
    Top = 430
    Width = 1052
  end
  inherited Panel1: TPanel
    Width = 1052
    Visible = False
    inherited BitBtn1: TBitBtn
      Left = 890
    end
    inherited BitBtn2: TBitBtn
      Left = 978
    end
  end
  object dbgAll: TcxGrid [2]
    Left = 0
    Top = 71
    Width = 800
    Height = 359
    Align = alClient
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -13
    Font.Name = 'Tahoma'
    Font.Style = [fsBold]
    ParentFont = False
    TabOrder = 2
    LookAndFeel.Kind = lfStandard
    object tvAll: TcxGridDBTableView
      NavigatorButtons.ConfirmDelete = False
      NavigatorButtons.First.Visible = True
      NavigatorButtons.PriorPage.Visible = True
      NavigatorButtons.Prior.Visible = True
      NavigatorButtons.Next.Visible = True
      NavigatorButtons.NextPage.Visible = True
      NavigatorButtons.Last.Visible = True
      NavigatorButtons.Insert.Visible = False
      NavigatorButtons.Append.Visible = False
      NavigatorButtons.Delete.Visible = False
      NavigatorButtons.Edit.Visible = False
      NavigatorButtons.Post.Visible = False
      NavigatorButtons.Cancel.Visible = False
      NavigatorButtons.Refresh.Visible = False
      NavigatorButtons.SaveBookmark.Visible = False
      NavigatorButtons.GotoBookmark.Enabled = False
      NavigatorButtons.GotoBookmark.Visible = False
      NavigatorButtons.Filter.Visible = False
      FilterBox.CustomizeDialog = False
      FilterBox.Visible = fvNever
      DataController.DataSource = dlgDS
      DataController.Summary.DefaultGroupSummaryItems = <>
      DataController.Summary.FooterSummaryItems = <
        item
          Kind = skCount
          FieldName = 'FIO'
          Column = tvAllFIO
        end>
      DataController.Summary.SummaryGroups = <>
      DataController.Summary.Options = [soNullIgnore]
      OptionsBehavior.CellHints = True
      OptionsBehavior.FocusFirstCellOnNewRecord = True
      OptionsBehavior.IncSearch = True
      OptionsCustomize.ColumnFiltering = False
      OptionsCustomize.ColumnGrouping = False
      OptionsData.CancelOnExit = False
      OptionsData.Deleting = False
      OptionsData.DeletingConfirmation = False
      OptionsData.Editing = False
      OptionsData.Inserting = False
      OptionsView.NavigatorOffset = 5
      OptionsView.NoDataToDisplayInfoText = '<'#1053#1077#1090' '#1076#1072#1085#1085#1099#1093'>'
      OptionsView.CellAutoHeight = True
      OptionsView.CellTextMaxLineCount = 1
      OptionsView.ColumnAutoWidth = True
      OptionsView.ExpandButtonsForEmptyDetails = False
      OptionsView.Footer = True
      OptionsView.GroupByBox = False
      OptionsView.HeaderEndEllipsis = True
      OptionsView.Indicator = True
      OptionsView.ShowColumnFilterButtons = sfbAlways
      Styles.Content = DMInv.cxData
      Styles.IncSearch = DMInv.cxGreenText
      Styles.Header = DMInv.cxSiniyText
      object tvAllFIO: TcxGridDBColumn
        Caption = #1060#1048#1054
        DataBinding.FieldName = 'FIO'
        Width = 252
      end
      object tvAllPODR_NAME: TcxGridDBColumn
        Caption = #1044#1086#1083#1078#1085#1086#1089#1090#1100
        DataBinding.FieldName = 'PODR_NAME'
        Width = 220
      end
      object tvAllPODR1: TcxGridDBColumn
        Caption = #1055#1086#1076#1088#1072#1079#1076#1077#1083#1077#1085#1080#1077
        DataBinding.FieldName = 'PODR1'
        Width = 198
      end
    end
    object cxGridLevel1: TcxGridLevel
      GridView = tvAll
    end
  end
  object dbgSum: TcxGrid [3]
    Left = 808
    Top = 71
    Width = 244
    Height = 359
    Align = alRight
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -13
    Font.Name = 'Tahoma'
    Font.Style = [fsBold]
    ParentFont = False
    TabOrder = 3
    LookAndFeel.Kind = lfStandard
    object tvSum: TcxGridDBTableView
      NavigatorButtons.ConfirmDelete = False
      NavigatorButtons.First.Visible = True
      NavigatorButtons.PriorPage.Visible = True
      NavigatorButtons.Prior.Visible = True
      NavigatorButtons.Next.Visible = True
      NavigatorButtons.NextPage.Visible = True
      NavigatorButtons.Last.Visible = True
      NavigatorButtons.Insert.Visible = False
      NavigatorButtons.Append.Visible = False
      NavigatorButtons.Delete.Visible = False
      NavigatorButtons.Edit.Visible = False
      NavigatorButtons.Post.Visible = False
      NavigatorButtons.Cancel.Visible = False
      NavigatorButtons.Refresh.Visible = False
      NavigatorButtons.SaveBookmark.Visible = False
      NavigatorButtons.GotoBookmark.Enabled = False
      NavigatorButtons.GotoBookmark.Visible = False
      NavigatorButtons.Filter.Visible = False
      FilterBox.CustomizeDialog = False
      FilterBox.Visible = fvNever
      DataController.DataSource = dsSum
      DataController.Summary.DefaultGroupSummaryItems = <>
      DataController.Summary.FooterSummaryItems = <
        item
          Format = '0'
          Kind = skSum
          FieldName = 'COUNT_'
          Column = tvSumCOUNT_
        end>
      DataController.Summary.SummaryGroups = <>
      DataController.Summary.Options = [soNullIgnore]
      OptionsBehavior.CellHints = True
      OptionsBehavior.FocusFirstCellOnNewRecord = True
      OptionsBehavior.IncSearch = True
      OptionsCustomize.ColumnFiltering = False
      OptionsCustomize.ColumnGrouping = False
      OptionsData.CancelOnExit = False
      OptionsData.Deleting = False
      OptionsData.DeletingConfirmation = False
      OptionsData.Editing = False
      OptionsData.Inserting = False
      OptionsView.NavigatorOffset = 5
      OptionsView.NoDataToDisplayInfoText = '<'#1053#1077#1090' '#1076#1072#1085#1085#1099#1093'>'
      OptionsView.CellAutoHeight = True
      OptionsView.CellTextMaxLineCount = 1
      OptionsView.ColumnAutoWidth = True
      OptionsView.ExpandButtonsForEmptyDetails = False
      OptionsView.Footer = True
      OptionsView.GroupByBox = False
      OptionsView.HeaderEndEllipsis = True
      OptionsView.Indicator = True
      OptionsView.ShowColumnFilterButtons = sfbAlways
      Styles.Content = DMInv.cxData
      Styles.IncSearch = DMInv.cxGreenText
      Styles.Header = DMInv.cxSiniyText
      object tvSumPODR1: TcxGridDBColumn
        Caption = #1055#1086#1076#1088#1072#1079#1076'.'
        DataBinding.FieldName = 'PODR1'
      end
      object tvSumCOUNT_: TcxGridDBColumn
        Caption = #1050#1086#1083#1080#1095'. '#1095#1077#1083'.'
        DataBinding.FieldName = 'COUNT_'
      end
    end
    object cxGridLevel2: TcxGridLevel
      GridView = tvSum
    end
  end
  object cxSplitter1: TcxSplitter [4]
    Left = 800
    Top = 71
    Width = 8
    Height = 359
    HotZoneClassName = 'TcxSimpleStyle'
    AlignSplitter = salRight
    Control = dbgSum
  end
  object dxBarDockControl1: TdxBarDockControl [5]
    Left = 0
    Top = 45
    Width = 1052
    Height = 26
    Align = dalTop
    BarManager = dxBarManager1
  end
  inherited dlgDS: TDataSource
    DataSet = qAll
  end
  object dxBarManager1: TdxBarManager
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -12
    Font.Name = 'Segoe UI'
    Font.Style = []
    Categories.Strings = (
      'Default')
    Categories.ItemsVisibles = (
      2)
    Categories.Visibles = (
      True)
    ImageOptions.Images = DMInv.cxSmallImages
    PopupMenuLinks = <>
    UseSystemFont = True
    Left = 168
    Top = 192
    DockControlHeights = (
      0
      0
      0
      0)
    object dxBarManager1Bar1: TdxBar
      AllowClose = False
      AllowCustomizing = False
      AllowQuickCustomizing = False
      AllowReset = False
      Caption = 'main'
      CaptionButtons = <>
      DockControl = dxBarDockControl1
      DockedDockControl = dxBarDockControl1
      DockedLeft = 0
      DockedTop = 0
      FloatLeft = 444
      FloatTop = 201
      FloatClientWidth = 51
      FloatClientHeight = 22
      ItemLinks = <
        item
          Visible = True
          ItemName = 'bRefresh'
        end
        item
          BeginGroup = True
          Visible = True
          ItemName = 'bexport'
        end>
      NotDocking = [dsNone, dsLeft, dsTop, dsRight, dsBottom]
      OneOnRow = True
      Row = 0
      UseOwnFont = False
      UseRestSpace = True
      Visible = True
      WholeRow = False
    end
    object bRefresh: TdxBarButton
      Caption = #1054#1073#1085#1086#1074#1080#1090#1100
      Category = 0
      Hint = #1054#1073#1085#1086#1074#1080#1090#1100
      Visible = ivAlways
      ImageIndex = 55
      PaintStyle = psCaptionGlyph
      OnClick = bRefreshClick
    end
    object bexport: TdxBarButton
      Caption = ' '#1074' Excel'
      Category = 0
      Hint = ' '#1074' Excel'
      Visible = ivAlways
      ImageIndex = 48
      PaintStyle = psCaptionGlyph
      OnClick = bexportClick
    end
  end
  object qAll: TIBQuery
    Database = DMInv.DBRead
    Transaction = DMInv.IBTransaction1
    SQL.Strings = (
      
        'SELECT  (P.PLASTNAME||'#39' '#39'||P.PNAME||'#39' '#39'||COALESCE(P.PPATRONYMIC,' +
        #39' '#39')) AS fio,'
      '    dp.SDNAME AS podr_name, '#39#1044'/'#1089' '#1080' '#1075#1080#1084#1085#1072#1079#1080#1103#39' AS podr1'
      ''
      'FROM PEOPLE P'
      'INNER JOIN P_STATUS PS ON PS.PID = P.PID'
      ''
      'INNER JOIN ('
      'SELECT APU.PID, dp.sdid, dp.DPDATEIN, dp.DPDATEOUT, sd.SDNAME '
      'FROM DETI_PODRAZD_SC DP '
      'INNER JOIN SPEC_COND SC ON SC.SCID = DP.SCID '
      'INNER JOIN AGR_POLUCH_USLUG APU ON APU.AGID = SC.AGID '
      'INNER JOIN SYS_DIC SD ON SD.SDID = DP.SDID '
      ' where DP.DPTYPE = 1 AND SC.SCISDELETE IS NULL '
      'and  CURRENT_DATE BETWEEN CAST(dp.DPDATEIN AS DATE) '
      '    AND COALESCE(CAST(dp.DPDATEOUT AS DATE), CURRENT_DATE) '
      ') as dp on dp.pid = P.PID '
      'INNER JOIN'
      '('
      'SELECT t2.sdid'
      'FROM'
      '('
      'WITH   recursive'
      '   tree (SDNAME, SDID, SDPARID)'
      '   AS (SELECT SD.SDNAME, SD.SDID, sd.SDPARID FROM SYS_DIC SD'
      '      WHERE sd.SDPARID in (1400, 1411, 2125, 11930)'
      '      UNION ALL'
      '      SELECT SD1.SDNAME, SD1.SDID, sd1.SDPARID'
      ''
      '      FROM SYS_DIC SD1'
      '          INNER JOIN tree t '
      '           ON t.sdid = sd1.SDPARID)'
      ' SELECT  SDNAME, SDID, SDPARID FROM tree t'
      ') AS t2'
      ') AS podr ON podr.sdid = dp.SDID'
      'INNER JOIN'
      '('
      'SELECT PV.PID'
      'FROM P_VIZIT PV'
      'WHERE PV.PVTIME_OUT IS NULL'
      'AND CURRENT_DATE >= CAST(PV.PVTIME_IN AS DATE)'
      ') AS vnutri on vnutri.pid = dp.PID'
      'WHERE PS.SDID = 1246'
      'AND P.PISDELETE IS NULL'
      'UNION'
      '--'#1089#1090#1072#1088#1096#1072#1103' '#1096#1082#1086#1083#1072
      
        'SELECT  (P.PLASTNAME||'#39' '#39'||P.PNAME||'#39' '#39'||COALESCE(P.PPATRONYMIC,' +
        #39' '#39')) AS fio,'
      'dp.SDNAME AS podr_name , '#39#1057#1090#1072#1088#1096#1072#1103' '#1096#1082#1086#1083#1072#39' AS podr1'
      'FROM PEOPLE P'
      'INNER JOIN P_STATUS PS ON PS.PID = P.PID'
      'INNER JOIN ('
      'SELECT APU.PID, dp.sdid, dp.DPDATEIN, dp.DPDATEOUT, sd.SDNAME '
      'FROM DETI_PODRAZD_SC DP '
      'INNER JOIN SPEC_COND SC ON SC.SCID = DP.SCID '
      'INNER JOIN AGR_POLUCH_USLUG APU ON APU.AGID = SC.AGID '
      'INNER JOIN SYS_DIC SD ON SD.SDID = DP.SDID '
      ' where DP.DPTYPE = 1 AND SC.SCISDELETE IS NULL '
      'and  CURRENT_DATE BETWEEN CAST(dp.DPDATEIN AS DATE) '
      '    AND COALESCE(CAST(dp.DPDATEOUT AS DATE), CURRENT_DATE) '
      ') as dp on dp.pid = P.PID '
      'INNER JOIN'
      '('
      'SELECT t2.sdid'
      'FROM'
      '('
      'WITH   recursive'
      '   tree (SDNAME, SDID, SDPARID)'
      '   AS (SELECT SD.SDNAME, SD.SDID, sd.SDPARID FROM SYS_DIC SD'
      '      WHERE sd.SDPARID in (1412, 1413)'
      '      UNION ALL'
      '      SELECT SD1.SDNAME, SD1.SDID, sd1.SDPARID'
      ''
      '      FROM SYS_DIC SD1'
      '          INNER JOIN tree t '
      '           ON t.sdid = sd1.SDPARID)'
      ' SELECT  SDNAME, SDID, SDPARID FROM tree t'
      ') AS t2'
      ') AS podr ON podr.sdid = dp.SDID'
      'WHERE PS.SDID = 1246  AND P.PISDELETE IS NULL'
      'UNION'
      '--'#1089#1086#1090#1088#1091#1076#1085#1080#1082#1080
      
        'SELECT  (P.PLASTNAME||'#39' '#39'||P.PNAME||'#39' '#39'||COALESCE(P.PPATRONYMIC,' +
        #39' '#39')) AS fio,'
      'SD1.SDNAME AS podr_name, '#39#1057#1086#1090#1088#1091#1076#1085#1080#1082#1080#39' AS podr1'
      'FROM PEOPLE P'
      'INNER JOIN DOLJNOST_PEOPLE d ON d.PID = P.PID'
      'INNER JOIN DOLJNOST D1 ON d1.DOLID = d.DOLID'
      'INNER JOIN SYS_DIC SD1 ON SD1.SDID = d1.SDID'
      'WHERE P.PISDELETE IS NULL AND d.DOLISDELETE IS NULL'
      
        'AND CURRENT_DATE BETWEEN D.DOLDATEBEGIN AND COALESCE(d.DOLDATEEN' +
        'D, CURRENT_DATE)'
      ''
      'ORDER by 3,2,1')
    Left = 296
    object qAllFIO: TIBStringField
      FieldName = 'FIO'
      ProviderFlags = []
      Size = 767
    end
    object qAllPODR_NAME: TIBStringField
      FieldName = 'PODR_NAME'
      Origin = '"SYS_DIC"."SDNAME"'
      Size = 255
    end
    object qAllPODR1: TIBStringField
      FieldName = 'PODR1'
      ProviderFlags = []
      FixedChar = True
      Size = 14
    end
  end
  object dsSum: TDataSource
    DataSet = qSum
    Left = 704
    Top = 8
  end
  object qSum: TIBQuery
    Database = DMInv.DBRead
    Transaction = DMInv.IBTransaction1
    SQL.Strings = (
      
        'SELECT '#39#1044'/'#1089' ('#1085#1072' '#1090#1077#1088#1088#1080#1090#1086#1088#1080#1080')'#39' AS podr1, COUNT(DISTINCT P.PID) AS ' +
        'COUNT_'
      'FROM PEOPLE P'
      'INNER JOIN P_STATUS PS ON PS.PID = P.PID'
      'INNER JOIN ('
      'SELECT APU.PID, dp.sdid, dp.DPDATEIN, dp.DPDATEOUT, sd.SDNAME '
      'FROM DETI_PODRAZD_SC DP '
      'INNER JOIN SPEC_COND SC ON SC.SCID = DP.SCID '
      'INNER JOIN AGR_POLUCH_USLUG APU ON APU.AGID = SC.AGID '
      'INNER JOIN SYS_DIC SD ON SD.SDID = DP.SDID '
      ' where DP.DPTYPE = 1 AND SC.SCISDELETE IS NULL '
      'and  CURRENT_DATE BETWEEN CAST(dp.DPDATEIN AS DATE) '
      '    AND COALESCE(CAST(dp.DPDATEOUT AS DATE), CURRENT_DATE) '
      ') as dp on dp.pid = P.PID '
      'INNER JOIN'
      '('
      'SELECT t2.sdid'
      'FROM'
      '('
      'WITH   recursive'
      '   tree (SDNAME, SDID, SDPARID)'
      '   AS (SELECT SD.SDNAME, SD.SDID, sd.SDPARID FROM SYS_DIC SD'
      '      WHERE sd.SDPARID in (1400)'
      '      UNION ALL'
      '      SELECT SD1.SDNAME, SD1.SDID, sd1.SDPARID'
      ''
      '      FROM SYS_DIC SD1'
      '          INNER JOIN tree t '
      '           ON t.sdid = sd1.SDPARID)'
      ' SELECT  SDNAME, SDID, SDPARID FROM tree t'
      ') AS t2'
      ') AS podr ON podr.sdid = dp.SDID'
      'INNER JOIN'
      '('
      'SELECT PV.PID'
      'FROM P_VIZIT PV'
      'WHERE PV.PVTIME_OUT IS NULL'
      'AND CURRENT_DATE >= CAST(PV.PVTIME_IN AS DATE)'
      ') AS vnutri on vnutri.pid = dp.PID'
      'WHERE PS.SDID = 1246'
      'AND P.PISDELETE IS NULL'
      'GROUP BY 1'
      'UNION'
      
        'SELECT '#39#1043#1080#1084#1085#1072#1079#1080#1103'('#1085#1072' '#1090#1077#1088#1088#1080#1090#1086#1088#1080#1080')'#39' AS podr1, COUNT(DISTINCT P.PID)' +
        ' AS COUNT_'
      'FROM PEOPLE P'
      'INNER JOIN P_STATUS PS ON PS.PID = P.PID'
      'INNER JOIN ('
      'SELECT APU.PID, dp.sdid, dp.DPDATEIN, dp.DPDATEOUT, sd.SDNAME '
      'FROM DETI_PODRAZD_SC DP '
      'INNER JOIN SPEC_COND SC ON SC.SCID = DP.SCID '
      'INNER JOIN AGR_POLUCH_USLUG APU ON APU.AGID = SC.AGID '
      'INNER JOIN SYS_DIC SD ON SD.SDID = DP.SDID '
      ' where DP.DPTYPE = 1 AND SC.SCISDELETE IS NULL '
      'and  CURRENT_DATE BETWEEN CAST(dp.DPDATEIN AS DATE) '
      '    AND COALESCE(CAST(dp.DPDATEOUT AS DATE), CURRENT_DATE) '
      ') as dp on dp.pid = P.PID '
      'INNER JOIN'
      '('
      'SELECT t2.sdid'
      'FROM'
      '('
      'WITH   recursive'
      '   tree (SDNAME, SDID, SDPARID)'
      '   AS (SELECT SD.SDNAME, SD.SDID, sd.SDPARID FROM SYS_DIC SD'
      '      WHERE sd.SDPARID in (1411)'
      '      UNION ALL'
      '      SELECT SD1.SDNAME, SD1.SDID, sd1.SDPARID'
      ''
      '      FROM SYS_DIC SD1'
      '          INNER JOIN tree t '
      '           ON t.sdid = sd1.SDPARID)'
      ' SELECT  SDNAME, SDID, SDPARID FROM tree t'
      ') AS t2'
      ') AS podr ON podr.sdid = dp.SDID'
      'INNER JOIN'
      '('
      'SELECT PV.PID'
      'FROM P_VIZIT PV'
      'WHERE PV.PVTIME_OUT IS NULL'
      'AND CURRENT_DATE >= CAST(PV.PVTIME_IN AS DATE)'
      ') AS vnutri on vnutri.pid = dp.PID'
      'WHERE PS.SDID = 1246'
      'AND P.PISDELETE IS NULL'
      'GROUP BY 1'
      'UNION'
      '--'#1089#1090#1072#1088#1096#1072#1103' '#1096#1082#1086#1083#1072
      
        'SELECT '#39#1057#1090#1072#1088#1096#1072#1103' '#1096#1082#1086#1083#1072'('#1086#1073#1097#1077#1077' '#1082#1086#1083#1080#1095'. '#1091#1095#1077#1085#1080#1082#1086#1074')'#39' AS podr1, COUNT(DI' +
        'STINCT P.PID) AS COUNT_'
      'FROM PEOPLE P'
      'INNER JOIN P_STATUS PS ON PS.PID = P.PID'
      'INNER JOIN ('
      'SELECT APU.PID, dp.sdid, dp.DPDATEIN, dp.DPDATEOUT, sd.SDNAME '
      'FROM DETI_PODRAZD_SC DP '
      'INNER JOIN SPEC_COND SC ON SC.SCID = DP.SCID '
      'INNER JOIN AGR_POLUCH_USLUG APU ON APU.AGID = SC.AGID '
      'INNER JOIN SYS_DIC SD ON SD.SDID = DP.SDID '
      ' where DP.DPTYPE = 1 AND SC.SCISDELETE IS NULL '
      'and  CURRENT_DATE BETWEEN CAST(dp.DPDATEIN AS DATE) '
      '    AND COALESCE(CAST(dp.DPDATEOUT AS DATE), CURRENT_DATE) '
      ') as dp on dp.pid = P.PID '
      'INNER JOIN'
      '('
      'SELECT t2.sdid'
      'FROM'
      '('
      'WITH   recursive'
      '   tree (SDNAME, SDID, SDPARID)'
      '   AS (SELECT SD.SDNAME, SD.SDID, sd.SDPARID FROM SYS_DIC SD'
      '      WHERE sd.SDPARID in (1412, 1413)'
      '      UNION ALL'
      '      SELECT SD1.SDNAME, SD1.SDID, sd1.SDPARID'
      ''
      '      FROM SYS_DIC SD1'
      '          INNER JOIN tree t '
      '           ON t.sdid = sd1.SDPARID)'
      ' SELECT  SDNAME, SDID, SDPARID FROM tree t'
      ') AS t2'
      ') AS podr ON podr.sdid = dp.SDID'
      'WHERE PS.SDID = 1246  AND P.PISDELETE IS NULL'
      'GROUP BY 1'
      'UNION'
      
        'SELECT '#39#1071#1079#1099#1082#1086#1074#1086#1081' '#1083#1072#1075#1077#1088#1100'('#1085#1072' '#1090#1077#1088#1088#1080#1090#1086#1088#1080#1080')'#39' AS podr1, COUNT(DISTINCT' +
        ' P.PID) AS COUNT_'
      'FROM PEOPLE P'
      'INNER JOIN P_STATUS PS ON PS.PID = P.PID'
      'INNER JOIN ('
      'SELECT APU.PID, dp.sdid, dp.DPDATEIN, dp.DPDATEOUT, sd.SDNAME '
      'FROM DETI_PODRAZD_SC DP '
      'INNER JOIN SPEC_COND SC ON SC.SCID = DP.SCID '
      'INNER JOIN AGR_POLUCH_USLUG APU ON APU.AGID = SC.AGID '
      'INNER JOIN SYS_DIC SD ON SD.SDID = DP.SDID '
      ' where DP.DPTYPE = 1 AND SC.SCISDELETE IS NULL '
      'and  CURRENT_DATE BETWEEN CAST(dp.DPDATEIN AS DATE) '
      '    AND COALESCE(CAST(dp.DPDATEOUT AS DATE), CURRENT_DATE) '
      ') as dp on dp.pid = P.PID '
      'INNER JOIN'
      '('
      'SELECT t2.sdid'
      'FROM'
      '('
      'WITH   recursive'
      '   tree (SDNAME, SDID, SDPARID)'
      '   AS (SELECT SD.SDNAME, SD.SDID, sd.SDPARID FROM SYS_DIC SD'
      '      WHERE sd.SDPARID in (2125)'
      '      UNION ALL'
      '      SELECT SD1.SDNAME, SD1.SDID, sd1.SDPARID'
      ''
      '      FROM SYS_DIC SD1'
      '          INNER JOIN tree t '
      '           ON t.sdid = sd1.SDPARID)'
      ' SELECT  SDNAME, SDID, SDPARID FROM tree t'
      ') AS t2'
      ') AS podr ON podr.sdid = dp.SDID'
      'INNER JOIN'
      '('
      'SELECT PV.PID'
      'FROM P_VIZIT PV'
      'WHERE PV.PVTIME_OUT IS NULL'
      'AND CURRENT_DATE >= CAST(PV.PVTIME_IN AS DATE)'
      ') AS vnutri on vnutri.pid = dp.PID'
      'WHERE PS.SDID = 1246'
      'AND P.PISDELETE IS NULL'
      'GROUP BY 1'
      'UNION'
      
        'SELECT '#39#1055#1072#1085#1089#1080#1086#1085'('#1085#1072' '#1090#1077#1088#1088#1080#1090#1086#1088#1080#1080')'#39' AS podr1, COUNT(DISTINCT P.PID) ' +
        'AS COUNT_'
      'FROM PEOPLE P'
      'INNER JOIN P_STATUS PS ON PS.PID = P.PID'
      'INNER JOIN ('
      'SELECT APU.PID, dp.sdid, dp.DPDATEIN, dp.DPDATEOUT, sd.SDNAME '
      'FROM DETI_PODRAZD_SC DP '
      'INNER JOIN SPEC_COND SC ON SC.SCID = DP.SCID '
      'INNER JOIN AGR_POLUCH_USLUG APU ON APU.AGID = SC.AGID '
      'INNER JOIN SYS_DIC SD ON SD.SDID = DP.SDID '
      ' where DP.DPTYPE = 1 AND SC.SCISDELETE IS NULL '
      'and  CURRENT_DATE BETWEEN CAST(dp.DPDATEIN AS DATE) '
      '    AND COALESCE(CAST(dp.DPDATEOUT AS DATE), CURRENT_DATE) '
      ') as dp on dp.pid = P.PID '
      'INNER JOIN'
      '('
      'SELECT t2.sdid'
      'FROM'
      '('
      'WITH   recursive'
      '   tree (SDNAME, SDID, SDPARID)'
      '   AS (SELECT SD.SDNAME, SD.SDID, sd.SDPARID FROM SYS_DIC SD'
      '      WHERE sd.SDPARID in (11930)'
      '      UNION ALL'
      '      SELECT SD1.SDNAME, SD1.SDID, sd1.SDPARID'
      ''
      '      FROM SYS_DIC SD1'
      '          INNER JOIN tree t '
      '           ON t.sdid = sd1.SDPARID)'
      ' SELECT  SDNAME, SDID, SDPARID FROM tree t'
      ') AS t2'
      ') AS podr ON podr.sdid = dp.SDID'
      'INNER JOIN'
      '('
      'SELECT PV.PID'
      'FROM P_VIZIT PV'
      'WHERE PV.PVTIME_OUT IS NULL'
      'AND CURRENT_DATE >= CAST(PV.PVTIME_IN AS DATE)'
      ') AS vnutri on vnutri.pid = dp.PID'
      'WHERE PS.SDID = 1246'
      'AND P.PISDELETE IS NULL'
      'GROUP BY 1'
      'UNION'
      '--'#1089#1086#1090#1088#1091#1076#1085#1080#1082#1080
      
        'SELECT   '#39#1057#1086#1090#1088#1091#1076#1085#1080#1082#1080'('#1086#1073#1097#1077#1077' '#1082#1086#1083#1080#1095'-'#1074#1086')'#39' AS podr1, COUNT(DISTINCT P' +
        '.PID) AS COUNT_'
      'FROM PEOPLE P'
      'INNER JOIN DOLJNOST_PEOPLE d ON d.PID = P.PID'
      'INNER JOIN DOLJNOST D1 ON d1.DOLID = d.DOLID'
      'INNER JOIN SYS_DIC SD1 ON SD1.SDID = d1.SDID'
      'WHERE P.PISDELETE IS NULL AND d.DOLISDELETE IS NULL'
      
        'AND CURRENT_DATE BETWEEN D.DOLDATEBEGIN AND COALESCE(d.DOLDATEEN' +
        'D, CURRENT_DATE)'
      'GROUP BY 1')
    Left = 744
    Top = 8
    object qSumCOUNT_: TIntegerField
      FieldName = 'COUNT_'
      ProviderFlags = []
    end
    object qSumPODR1: TIBStringField
      FieldName = 'PODR1'
      ProviderFlags = []
      FixedChar = True
      Size = 36
    end
  end
  object SD1: TSaveDialog
    InitialDir = 'c:\'
    Options = [ofOverwritePrompt, ofHideReadOnly, ofEnableSizing]
    Left = 704
    Top = 120
  end
end
